package com.six.elemo_manger.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.avos.avoscloud.AVObject;
import com.bumptech.glide.Glide;
import com.six.elemo_manger.R;

import java.util.List;

public class TestAdapter extends BaseAdapter {
    private List<AVObject> list;
    private Context context;

    public TestAdapter(List<AVObject> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //将布局文件转化为View对象
        View view = LayoutInflater.from(context).inflate(R.layout.item_online,null);

        /**
         * 找到item布局文件中对应的控件
         */
        ImageView img_online = (ImageView) view.findViewById(R.id.img_online);
        TextView tv_name = (TextView) view.findViewById(R.id.tv_online_name);
        TextView tv_price = (TextView) view.findViewById(R.id.tv_online_price);

        /**
         * 设置控件的对应属性值
         */
         Glide.with(context).load(list.get(position).getString("food_Img")).into(img_online);
         tv_name.setText(list.get(position).getString("food_Name"));
         tv_price.setText(list.get(position).getString("food_Price"));


        return view;

    }
}
